/**
 * 定义页面对应的后台处理类完整路径。
 */
var clsUrl = basePath + 'JarpListener?className=cn.com.zsc.hr.EmployeeManage';

/**
 * 操作类型(新增：0 修改：1)
 */
var status;

/**
 * 图片地址
 */
var photoPath;

/**
 * 图片类型
 */
var img_reg = /\.([jJ][pP][gG]){1}$|\.([jJ][pP][eE][gG]){1}$|\.([gG][iI][fF]){1}$|\.([pP][nN][gG]){1}$|\.([bB][mM][pP]){1}$/

/**
 * 暂无图片 
 */
var nonImage = basePath + 'images/zanwu.jpg';

Ext.onReady(function(){
	Ext.QuickTips.init();

	/**
	 * 性别数据源
	 */
	var sexStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '5'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 性别控件
	 */
	var sexComboBox = new Ext.form.ComboBox({
		fieldLabel : '性别',
		id : 'sex',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:sexStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true
	});
	
	/**
	 * 用工形式数据源
	 */
	var epModeStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '6'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 用工形式控件
	 */
	var epModeComboBox = new Ext.form.ComboBox({
		fieldLabel : '用工形式',
		id : 'epMode',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:epModeStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true
	});

	/**
	 * 政治面貌数据源
	 */
	var pVisageStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '8'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 政治面貌控件
	 */
	var pVisageComboBox = new Ext.form.ComboBox({
		fieldLabel : '政治面貌',
		id : 'pVisage',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:pVisageStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true
	});
	
	/**
	 * 所属部门数据源
	 */
	var deptStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '9'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 所属部门控件
	 */
	var deptComboBox = new Ext.form.ComboBox({
		fieldLabel : '所属部门',
		id : 'dept',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:deptStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true
	});

	/**
	 * 文化程度数据源
	 */
	var educationStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '11'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 文化程度控件
	 */
	var educationComboBox = new Ext.form.ComboBox({
		fieldLabel : '文化程度',
		id : 'education',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:educationStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true
	});

	/**
	 * 组别数据源
	 */
	var termStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '15'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 组别控件
	 */
	var termComboBox = new Ext.form.ComboBox({
		fieldLabel : '组别',
		id : 'term',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:termStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true
	});
	
	/**
	 * 岗位数据源
	 */
	var postStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '40'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 岗位控件
	 */
	var postComboBox = new Ext.form.ComboBox({
		fieldLabel : '岗位',
		id : 'post',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:postStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true
	});
	
	/**
	 * 职务数据源
	 */
	var dutiesStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '41'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 职务控件
	 */
	var dutiesComboBox = new Ext.form.ComboBox({
		fieldLabel : '职务',
		id : 'duties',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:dutiesStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true
	});
	
	/**
	 * 是否离职数据源
	 */
	var leftJobStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '12'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 是否离职控件
	 */
	var leftJob = new Ext.form.ComboBox({
		fieldLabel : '是否离职',
		id : 'leftJob',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:leftJobStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true,
		listeners:{'render':function() {
				this.setValue(41);
			}
		}
	});
	
	/**
	 * 是否购买保险数据源
	 */
	var insuranceStore=new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : comboBoxUrl + '12'
		}),
		reader : new Ext.data.JsonReader({
			fields : [
			{name:'CL_CODE'},
			{name:'CL_NAME'}
		]
		}),
		autoLoad : true
	});
	
	/**
	 * 是否购买保险控件
	 */
	var insurance = new Ext.form.ComboBox({
		fieldLabel : '是否购买保险',
		id : 'insurance',
		width : 90,
		displayField : 'CL_NAME',
		valueField : 'CL_CODE',
		emptyText : '请选择',
		store:insuranceStore,
		mode : 'local',
		editable  : false,
		triggerAction : 'all',
		selectOnFocus : true,
		listeners:{'render':function() {
				this.setValue(40);
			}
		}
	});
	
	/**
	 * 学校协议时间控件
	 */
	var agreement = new Ext.form.DateField({
		id:'agreement',
        fieldLabel:"学校协议时间",
        name:'agreement',
        format:'Y-m-d',
        editable:false,
        width:90
    });
    
    /**
	 * 到本单位时间
	 */
	var arrDate = new Ext.form.DateField({
		id:'arrDate',
        fieldLabel:"到本单位时间",
        name:'arrDate',
        format:'Y-m-d',
        editable:false,
        width:90
    });
    
    /**
	 * 结束实习/兼职时间
	 */
	var endDate = new Ext.form.DateField({
		id:'endDate',
        fieldLabel:"结束兼职时间",
        name:'endDate',
        format:'Y-m-d',
        editable:false,
        width:90
    });
    
    /**
	 * 出生年月
	 */
	var birthday = new Ext.form.DateField({
		id:'birthday',
        fieldLabel:"出生年月",
        name:'birthday',
        format:'Y-m-d',
        editable:false,
        width:90
    });
    
    /**
	 * 进校时间
	 */
	var inDate = new Ext.form.DateField({
		id:'inDate',
        fieldLabel:"进校时间",
        name:'inDate',
        format:'Y-m-d',
        editable:false,
        width:90
    });
    
    /**
	 * 毕业时间
	 */
	var graduation = new Ext.form.DateField({
		id:'graduation',
        fieldLabel:"毕业时间",
        name:'graduation',
        format:'Y-m-d',
        editable:false,
        width:90
    });
	
	var storereader= new Ext.data.JsonReader({
		//为分页增加
		root : 'results',
        totalProperty : 'totalCount',
        
    	fields:[
    		{name :'EID'},
    		{name :'WORKID'},
    		{name :'ENAME'},
    		{name :'SEX'},
    		{name :'AGE'},
    		{name :'ICNO'},
    		{name :'RPRADD'},
    		{name :'LIVEADD'},
    		{name :'TEL'},
    		{name :'EPMODE'},
    		{name :'TLIMIT'},
    		{name :'PVISAGE'},
    		{name :'DEPT'},
    		{name :'GSCH'},
    		{name :'EDUCATION'},
    		{name :'TERM'},
    		{name :'FNAME'},
    		{name :'FAGE'},
    		{name :'FRELATION'},
    		{name :'FUNITS'},
    		{name :'PHOTO'},
    		{name :'REMARKED'},
    		{name :'POST'},
    		{name :'DUTIES'},
    		{name :'BIRTHDAY'},
    		{name :'HEIGHT'},
    		{name :'ARRDATE'},
    		{name :'SPECIALTY'},
    		{name :'WORKAGE'},
    		{name :'LEFTJOB'},
    		{name :'SPECIAL'},
    		{name :'INDATE'},
    		{name :'GRADUATION'},
    		{name :'AGREEMENT'},
    		{name :'ENDDATE'},
    		{name :'TEACHER'},
    		{name :'INSURANCE'},
    		
    		{name :'SHOW_SEX'},
    		{name :'SHOW_EPMODE'},
    		{name :'SHOW_PVISAGE'},
    		{name :'SHOW_DEPT'},
    		{name :'SHOW_EDUCATION'},
    		{name :'SHOW_TERM'},
    		{name :'SHOW_POST'},
    		{name :'SHOW_DUTIES'},
    		{name :'SHOW_LEFTJOB'},
    		{name :'SHOW_INSURANCE'}
    	]
	});
		
	/**
	 * 查询分页数据
	 */
	var store = new Ext.data.Store({
		reader:storereader,
		proxy:new Ext.data.HttpProxy({
			url:clsUrl+'&methodName=getEmployee&&paramCount=3'
		})
	});
     
	/**
	 * 分页Panel
	 */
	var toolpanel = new Ext.PagingToolbar({
                    pageSize:20,
                    store:store,
                    storeParams : {
                            className : 'cn.com.zsc.hr.EmployeeManage',
                            methodName : 'getEmployee',
                            paramCount : '2',
                            param_0 : '0',
                            param_1 : '20'
                        },
                        paramNames : {
                            start : 'param_0',
                            limit : 'param_1'
                        },
                    displayInfo: true,
                    displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
                    emptyMsg: '没有记录'
                });
	
	/**
	 * 用户列表
	 */
	var basegrid = new Ext.grid.GridPanel( {
		id :'basegrid',
		store :store,
		split :true,
		bodyStyle:'5px 15px 0',
		region :'center',
		border :false,
		enableColumnMove:false,                                           
	  	enableHdMenu:false,
		frame :false,
		autoScroll :true,
    	columns: [
     	            new Ext.grid.RowNumberer(),
    	          	{id:'eid',name:'eid', header:'雇员编号',enableColumnMove:false,sortable:true,hidden:true,hideCollapseTool:false, enableHdMenu:false,enableColumnResize :false,dataIndex: 'EID'},
    	          	{id:'workID',name:'workID', header:'工号',width:80,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'WORKID'},
    	          	{id:'eName',name:'eName',header:'姓名',width:70,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'ENAME'},
    	          	{header:'性别',width:40,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_SEX'},
    	          	{id:'sex',name:'sex',header:'性别',width:40,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SEX'},
    	          	{header:'所属部门',width:60,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_DEPT'},
    	          	{id:'dept',name:'dept',header:'所属部门',width:70,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'DEPT'},
    	          	{header:'岗位',width:60,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_POST'},
    	          	{id:'post',name:'post',header:'岗位',width:60,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'POST'},
    	          	{header:'职务',width:60,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_DUTIES'},
    	          	{id:'duties',name:'duties',header:'职务',width:60,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'DUTIES'},
    	          	{header:'组别',width:60,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_TERM'},
    	          	{id:'term',name:'term',header:'组别',width:60,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'TERM'},
    	          	{id:'birthday',name:'birthday',header:'出生年月',width:70,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'BIRTHDAY'},
    	          	{id:'age',name:'age',header:'年龄',width:40,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'AGE'},
    	          	{id:'height',name:'height',header:'身高',width:40,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'HEIGHT',renderer:function (val){if (val=='0'){return '';}else {return val;}}},
    	          	{id:'icno',name:'icno',header:'身份证号',width:160,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'ICNO'},
    	          	{id:'rprAdd',name:'rprAdd',header:'户籍地址',width:300,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'RPRADD'},
    	          	{id:'liveAdd',name:'liveAdd',header:'现地址',width:300,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'LIVEADD'},
    	          	{id:'tel',name:'tel',header:'联系方式',width:100,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'TEL'},
    	          	{header:'用工形式',width:80,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_EPMODE'},
    	          	{id:'epMode',name:'epMode',header:'用工形式',width:80,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'EPMODE'},
    	          	{id:'arrDate',name:'arrDate',header:'到本单位时间',width:90,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'ARRDATE'},
    	          	{id:'workAge',name:'workAge',header:'工龄',width:40,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'WORKAGE',renderer:function (val){if (val=='0'){return '';}else {return val;}}},
    	          	{header:'是否离职',width:60,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_LEFTJOB'},
    	          	{id:'leftJob',name:'leftJob',header:'是否离职',width:60,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'LEFTJOB'},
    	          	{id:'fRelation',name:'fRelation',header:'家庭成员关系',width:90,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'FRELATION'},
    	          	{id:'fName',name:'fName',header:'家庭成员姓名',width:90,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'FNAME'},
    	          	{id:'fAge',name:'fAge',header:'家庭成员年龄',width:90,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'FAGE'},
    	          	{id:'fUnits',name:'fUnits',header:'工作单位',width:200,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'FUNITS'},
    	          	{header:'政治面貌',width:80,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_PVISAGE'},
    	          	{id:'pVisage',name:'pVisage',header:'政治面貌',width:80,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'PVISAGE'},
    	          	{id:'gsch',name:'gsch',header:'毕业院校',width:200,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'GSCH'},
    	          	{header:'文化程度',width:80,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_EDUCATION'},
    	          	{id:'education',name:'education',header:'文化程度',width:80,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'EDUCATION'},
    	          	{id:'special',name:'special',header:'专业',width:80,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SPECIALTY'},
    	          	{id:'inDate',name:'inDate',header:'进校时间',width:70,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'INDATE'},
    	          	{id:'graduation',name:'graduation',header:'毕业时间',width:70,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'GRADUATION'},
    	          	{id:'agreement',name:'agreement',header:'与学校协议时间',width:95,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'AGREEMENT'},
    	          	{id:'endDate',name:'endDate',header:'结束实习/兼职时间',width:110,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'ENDDATE'},
    	          	{id:'teacher',name:'teacher',header:'实习老师',width:70,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'TEACHER'},
    	          	{header:'是否购买保险',width:90,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SHOW_INSURANCE'},
    	          	{id:'insurance',name:'insurance',header:'是否购买保险',width:90,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'INSURANCE'},
    	          	{id:'specialty',name:'specialty',header:'特长',width:80,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'SPECIAL'},
    	          	{id:'remarked',name:'remarked',header:'备注',width:300,sortable:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'REMARKED'},
    	          	{id:'photo',name:'photo',header:'照片路径',width:300,sortable:true,hidden:true,enableColumnMove:false,enableHdMenu:false,enableColumnResize :false, dataIndex: 'PHOTO'}
    	],
    	tbar:[
	    	     {
		    	     text:'新增',
		    	     iconCls:'add',
		      	   	 handler:function(){
		      	   	 	status=0;
		      	   	 	formPanel.getForm().reset();
		      	   	 	win.setTitle("新增兼职人员");
		      	   	 	win.show();
		    	     }
	      	   	},
	      	   	'-',
	      	   	{
		      	   	text:'修改',
		      	   	iconCls:'modify',
		      	   	handler:function(){
	      	   			status=1;
	      	   			var record = basegrid.getSelectionModel().getSelected(); 
	   		       		if(!record){   
			   		        Ext.Msg.show({
										title : '提示',
										width:210,
										msg : '请选择要修改的兼职人员',
										buttons : Ext.Msg.OK,
										icon : Ext.Msg.ERROR
									});
						}else{
			      	   		if(record){
								win.setTitle("修改兼职人员");
			            	   	win.show();
			            	   	
			            	   	var record = basegrid.getSelectionModel().getSelected();
								
								Ext.getCmp("eid").setValue(record.data.EID);
								Ext.getCmp("workID").setValue(record.data.WORKID);
								Ext.getCmp("eName").setValue(record.data.ENAME);
								Ext.getCmp("sex").setValue(record.data.SEX==0?"":record.data.SEX);
								Ext.getCmp("age").setValue(record.data.AGE==0?"":record.data.AGE);
								Ext.getCmp("post").setValue(record.data.POST==0?"":record.data.POST);
								Ext.getCmp("duties").setValue(record.data.DUTIES==0?"":record.data.DUTIES);
								Ext.getCmp("birthday").setValue(record.data.BIRTHDAY);
								Ext.getCmp("height").setValue(record.data.HEIGHT==0?"":record.data.HEIGHT);
								Ext.getCmp("education").setValue(record.data.EDUCATION==0?"":record.data.EDUCATION);
								Ext.getCmp("pVisage").setValue(record.data.PVISAGE==0?"":record.data.PVISAGE);
								Ext.getCmp("tel").setValue(record.data.TEL);
								Ext.getCmp("icno").setValue(record.data.ICNO);
								Ext.getCmp("rprAdd").setValue(record.data.RPRADD);
								Ext.getCmp("liveAdd").setValue(record.data.LIVEADD);
								Ext.getCmp("epMode").setValue(record.data.EPMODE==0?"":record.data.EPMODE);
								Ext.getCmp("arrDate").setValue(record.data.ARRDATE);
								Ext.getCmp("dept").setValue(record.data.DEPT==0?"":record.data.DEPT);
								Ext.getCmp("gsch").setValue(record.data.GSCH);
								Ext.getCmp("term").setValue(record.data.TERM==0?"":record.data.TERM);
								Ext.getCmp("fName").setValue(record.data.FNAME);
								Ext.getCmp("fAge").setValue(record.data.FAGE==0?"":record.data.FAGE);
                                Ext.getCmp("fRelation").setValue(record.data.FRELATION);
                                Ext.getCmp("fUnits").setValue(record.data.FUNITS);
								Ext.getCmp("remarked").setValue(record.data.REMARKED);
								Ext.getCmp("specialty").setValue(record.data.SPECIALTY);
								Ext.getCmp("workAge").setValue(record.data.WORKAGE==0?"":record.data.WORKAGE);
								Ext.getCmp("leftJob").setValue(record.data.LEFTJOB);
								
								Ext.getCmp("special").setValue(record.data.SPECIAL);
								Ext.getCmp("inDate").setValue(record.data.INDATE);
								Ext.getCmp("graduation").setValue(record.data.GRADUATION);
								Ext.getCmp("agreement").setValue(record.data.AGREEMENT);
								Ext.getCmp("endDate").setValue(record.data.ENDDATE);
								Ext.getCmp("teacher").setValue(record.data.TEACHER);
								Ext.getCmp("insurance").setValue(record.data.INSURANCE);
								
								var photoPath = record.data.PHOTO;
								if(photoPath=="") {
								    photoPath = basePath + 'images/zanwu.jpg';
								} else {
								    photoPath = photoPath.substring(photoPath.indexOf("photo"), photoPath.length);
									photoPath = photoPath.replace("$","\\");	
								}
								Ext.getCmp("photo").setValue(record.data.PHOTO);
     							Ext.get('imageBrowse').dom.src = photoPath;   
			            	}     
		      	   		}
	      	   		}
	      	   	},
	      	   	'-',
	      	   	{
		      	   	text:'删除',
		      	   	iconCls:'delete',
		      	   	handler:del
	      	   	}
	      	   	
 	  ],
 	  bbar:toolpanel
	});
	
	/**
	 * formPanel
	 */
	var formPanel = new Ext.FormPanel({
		id : "fileUploadForm",
		bodyStyle:'padding:0px 15px 0',
		region:'center',
		layout:'form',
		fileUpload : true,
		frame:true,
		autoScroll: true,
		border: true,
		labelAlign:'right',
		labelWidth : 70,
		items : [{
			layout : 'column',
			labelAlign : 'right',
			items : [{
				layout : 'form',
				labelWidth : 70,
				labelAlign : 'right',
				columnWidth : .70,
				items: [{
					layout : 'column',
					labelAlign : 'right',
					items:[{
						layout : 'form',
						labelWidth : 70,
						labelAlign : 'right',
						columnWidth : .33,
						items: [
							{fieldLabel : '姓名',width : 90,name : 'eName',id : 'eName',xtype : 'textfield'},
							{fieldLabel : '年龄',width : 90,name : 'age',id : 'age',xtype : 'numberfield'},
							sexComboBox,
							{fieldLabel : '身高',width : 90,name : 'height',id : 'height',xtype : 'numberfield'}
						]
					},{
						layout : 'form',
						labelWidth : 60,
						labelAlign : 'right',
						columnWidth : .32,
						items: [
							birthday,
							{fieldLabel : '联系方式',width : 90,name : 'tel',id : 'tel',xtype : 'textfield'},
							educationComboBox,
							pVisageComboBox
						]
					},{
					    layout : 'form',
						labelWidth : 80,
						labelAlign : 'right',
						columnWidth : .35,
						items: [
							{fieldLabel : '专业',width : 90,name : 'special',id : 'special',xtype : 'textfield'},
							inDate,
							graduation,
							agreement
						]
					}]
				},{
					layout : 'column',
					labelAlign : 'right',
					items:[{
						layout : 'form',
						labelWidth : 70,
						labelAlign : 'right',
						columnWidth : .50,
						items: [
							{fieldLabel : '身份证号码',width : 180,name : 'icno',id : 'icno',xtype : 'textfield'}
						]
					},{
						layout : 'form',
						labelWidth : 60,
						labelAlign : 'right',
						columnWidth : .50,
						items: [
							{fieldLabel: '毕业院校',width:186,name:'gsch',id:'gsch',xtype:'textfield'}
						]
					}]
				},
				  {fieldLabel: '户籍地址',width:436,name:'rprAdd',id:'rprAdd',xtype:'textfield'},
		    	  {fieldLabel: '现住址',width:436,name:'liveAdd',id:'liveAdd',xtype:'textfield'},
		    	  {fieldLabel : '雇员编号',width : 100,name : 'eid',id : 'eid',xtype:'textfield',hidden:true,hideLabel:true},
		    	  {fieldLabel : '是否编制人员',width : 100,name : 'isFormal',id : 'isFormal',xtype:'textfield',hidden:true,hideLabel:true,
		    	  	listeners:{'render':function() {
		    	  			Ext.getCmp("isFormal").setValue('41');
		    	  		}
		    	  	}
		    	  }
				]
			},{
				  layout : 'form',
				  labelWidth : 60,
				  labelAlign : 'right',
				  columnWidth : .30,
				  items : [
							{fieldLabel : '照片预览',width:110,height:140,xtype:'box',autoEl : {
											id : 'imageBrowse',
											tag : 'img',
											src : nonImage,
											style : 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);'
										}}, 
							{fieldLabel : '上传照片',width : 140,name : 'photo',id : 'photo',xtype : 'textfield',inputType : 'file',listeners : {'render' : function() {
										var photoCmp = Ext.get('photo');
								
										photoCmp.on('change', function(field,newValue, oldValue) {
											var picPath = photoCmp.getValue();
											var url = 'file:///' + picPath;
											if(img_reg.test(url)){ 
												if (Ext.isIE) {
													var image = Ext.get('imageBrowse').dom;
													image.src = Ext.BLANK_IMAGE_URL;
													image.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = url;
												} else {
													// 支持FF
													Ext.get('imageBrowse').dom.src = Ext.get('imageBrowse').dom.files.item(0).getAsDataURL();
												}
												Ext.getCmp("save").enable();
											} else {
												Ext.getCmp("photo").markInvalid("无效的图片类型");
												Ext.getCmp("save").disable();
											}
										}, this);
									}
								}
							},
								{fieldLabel : '特长',width : 140,name : 'specialty',id : 'specialty',xtype : 'textfield'}
							
				  ]
			 }]
		},{
			layout : 'column',
			labelAlign : 'right',
			items : [{
				layout : 'form',
				labelWidth : 70,
				labelAlign : 'right',
				columnWidth : .24,
				items : [
						{fieldLabel:'工号',width:90,name:'workID',id:'workID',xtype:'textfield'},
						{fieldLabel:'工龄',width:90,name:'workAge',id:'workAge',xtype:'numberfield'},
						epModeComboBox,
						leftJob
						]
			}, {
				layout : 'form',
				labelWidth : 60,
				labelAlign : 'right',
				columnWidth : .24,
				items : [
						deptComboBox,
						termComboBox,
						postComboBox,
						dutiesComboBox
						]
			}, {
				layout : 'form',
				labelWidth : 80,
				labelAlign : 'right',
				columnWidth : .26,
				items : [
						arrDate,
						endDate,
						{fieldLabel:'实习老师',width:90,name:'teacher',id:'teacher',xtype:'textfield'},
						insurance
						]
			},{
				layout : 'form',
				labelWidth : 80,
				labelAlign : 'right',
				columnWidth : .26,
				items : [
						{fieldLabel:'家庭成员姓名',width:90,name:'fName',id:'fName',xtype:'textfield'},
						{fieldLabel:'家庭成员关系',width:90,name:'fRelation',id:'fRelation',xtype:'textfield'},
						{fieldLabel:'家庭成员年龄',width:90,name:'fAge',id:'fAge',xtype:'numberfield'},
						{fieldLabel:'工作单位',width:90,name:'fUnits',id:'fUnits',xtype:'textfield'}
						]
			}]
		},
		   {fieldLabel : '操作类型',width : 100,name : 'operateType',id : 'operateType',xtype:'textfield',hidden:true,hideLabel:true},
		   {fieldLabel:'备注',width:650,name:'remarked',id:'remarked',xtype:'textarea'}
		]
	});
	
	/**
	 * 保存取消按钮
	 */
	var win = new Ext.Window({
		title:'新增兼职人员',
		width:800,
		height:480,
		layout:'border',
		closeAction:'hide',
		modal:true,
		draggable:false,
		resizable:false,
		tbar:[
		      {
		      	  id:'save',
		    	  text:'保存',
		    	  iconCls:'save',
		    	  handler:update
		      },
		      '-',
		      {
		    	  text:'取消',
		    	  iconCls:'cancel',
		    	  handler:function(){
      	   			win.hide();
		      	  }
		      }
		],
		items:[formPanel],
		listeners:{'beforehide':function() {
				formPanel.getForm().getEl().dom.reset()
	    	  	formPanel.getForm().reset();
	    	  	Ext.get('imageBrowse').dom.src = nonImage;
			}
		}
	});
	
	var mainPanel = new Ext.Panel({
            id: 'mainPanel',
            region:'center',
            split:true,
            border:false,
            frame:true,
            layout: 'border',  
            items:[basegrid]
    });
    
	var viewport = new Ext.Viewport( {
		layout:'border',
		items: [mainPanel]
	});
	
	/**
	 * 兼职人员操作
	 */
	function update(){
		if(!saveValidate()){
		    return;	
		}
		
		if(status==0) {
			Ext.getCmp("operateType").setValue(0);
		} else {
			Ext.getCmp("operateType").setValue(1);
		}
		
		formPanel.body.mask('正在保存，请稍等', 'x-mask-loading');
			
		Ext.getCmp("fileUploadForm").getForm().submit({   	  
            url : "empManageServlet",   
            method : "POST",   
            success : function(form, action) {   
            	Ext.Msg.show({   
	    	   		title : '成功提示',
	    	   		width:200,
	   				msg : '保存成功！',  
		       		buttons : Ext.Msg.OK,   
		       		icon : Ext.Msg.INFO   
	   			});
	   			
	   			store.reload();
		   		win.hide();
		   		formPanel.getForm().getEl().dom.reset()
		   		formPanel.getForm().reset();
		   		Ext.get('imageBrowse').dom.src = nonImage;
		   		formPanel.body.unmask();
            },   
            failure : function(form, action) {   
                Ext.Msg.show({   
	    	   		title : '错误提示',
	    	   		width:200,
	   				msg : '数据库操作失败', 
		       		buttons : Ext.Msg.OK,   
		       		icon : Ext.Msg.ERROR   
		   		});  
		   		
		   		store.reload();
		   		win.hide();
                formPanel.body.unmask();
            }   
        });   
	}
		
	/**
	 * 删除兼职人员
	 */
	function del(){
		var record = basegrid.getSelectionModel().getSelected();
		
		if(!record){
			Ext.Msg.show({
				title:'提示',
				width:210,
				msg:'请选择要删除的兼职人员',
				buttons:Ext.Msg.OK,
				icon: Ext.Msg.ERROR 
			});	
		}	
		
		if(record){
			Ext.Msg.show({
				title:'提示',
				width:200,
				msg:'确定要删除兼职人员！', 
				buttons: Ext.Msg.YESNO,
	            icon: Ext.MessageBox.QUESTION,
				fn:function(btn){
					if( "yes" == btn){
						delProc()
					}
				}
			});
			
		}
					
	}
		
	function delProc(){
		var record = basegrid.getSelectionModel().getSelected();
		 
		var obj = new Object();
		obj.eid = record.data.EID;
		
		var url=clsUrl+'&methodName=deleteEmployee&paramCount=0'
		
    	httpReq=null;
		httpReq = getXMLHttpRequest();
    	httpReq.onreadystatechange = onDelRtn;
		httpReq.open("POST",url, true);
		httpReq.send(Ext.util.JSON.encode(obj));
	}
	
	function onDelRtn(){
		if(httpReq.readyState == 4){
		   	if(httpReq.status == 200){
		   		if(httpReq.responseText == "success"){
		   			Ext.Msg.show({   
		    	   		title : '成功提示',
		    	   		width:200,
		   				msg : '删除成功！',  
			       		buttons : Ext.Msg.OK,   
			       		icon : Ext.Msg.INFO   
		   			});
		   			store.reload();
		   			httpReq=null;
		   		}else{
		   			Ext.Msg.show({   
		    	   		title : '错误提示',
		    	   		width:200,
		   				msg :httpReq.responseText,  
			       		buttons : Ext.Msg.OK,   
			       		icon : Ext.Msg.ERROR   
		   			});  
		   			httpReq=null;
		   		}
		   	}
		}
	}
	
	/**
	 * 兼职人员验证
	 */
	function saveValidate(){
//		if(Ext.getCmp("eName").getValue()==""){
//			Ext.getCmp("eName").markInvalid("姓名不能为空");
//			return false;
//		}
//	
//		if(Ext.getCmp("age").getValue()==""){
//			Ext.getCmp("age").markInvalid("年龄不能为空");
//			return false;
//		}
//		
//		if(Ext.getCmp("sex").getValue()==""){
//			Ext.getCmp("sex").markInvalid("请选择性别");
//			return false;
//		}
//	
//		if(Ext.getCmp("icno").getValue()==""){
//			Ext.getCmp("icno").markInvalid("身份证不能为空");
//			return false;
//		}
//		
//		if(Ext.getCmp("dept").getValue()==""){
//			Ext.getCmp("dept").markInvalid("请选择部门");
//			return false;
//		}
//		
//        if(Ext.getCmp("term").getValue()==""){
//			Ext.getCmp("term").markInvalid("请选择组别");
//			return false;
//		}
		
		var regNum = /^[0-9]\d*$/;
		
		if(Ext.getCmp("tel").getValue()!="" && !regNum.test(Ext.getCmp("tel").getValue())) {
			Ext.getCmp("tel").markInvalid("只能输入数字");
			return false;
		}
		
		var icno = Ext.getCmp("icno").getValue();
		var isIDCard1=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
		var isIDCard2=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[A-Z])$/;
		
		if(icno!="" && !isIDCard1.test(icno) && !isIDCard2.test(icno)) {
			Ext.getCmp("icno").markInvalid("身份证号码格式错误");
			return false;
		}
	
		if(Ext.getCmp("arrDate").getValue() > Ext.getCmp("endDate").getValue()) {
			Ext.getCmp("arrDate").markInvalid("到本单位时间必须小于结束兼职时间");
			return false;
		}
		
		return true;
	}
		
	store.on('beforeload',function(thiz,options){
		mainPanel.body.mask('正在加载数据','x-mask-loading');
		options.params.param_2 = 41;	
    });
    
	store.on("load",function(){
		mainPanel.body.unmask();
	});
	
	store.load({
        params: {
            param_0: 0,
            param_1: 20
        }
    });
});